package com.example.fund.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.http.util.EncodingUtils;

import android.app.Activity;
import android.content.Context;

public class DataFileUtil {
	
    /**
     * 一、私有文件夹下的文件存取（/data/data/包名/files）
     * 
     * @param fileName
     * @param
     */ 
    public static void writeFileData(Activity activity,String fileName, String content) { 
        try { 
            FileOutputStream fout = activity.openFileOutput(fileName, Context.MODE_PRIVATE); 
            byte[] bytes = content.getBytes(); 
            fout.write(bytes); 
            fout.close(); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
    }
	
    /**
     * 读文件在./data/data/包名/files/下面
     * 
     * @param fileName
     * @return
     */ 
    public static String readFileData(Activity activity,String fileName) { 
        String res = ""; 
        try { 
            FileInputStream fin = activity.openFileInput(fileName); 
            int length = fin.available(); 
            byte[] buffer = new byte[length]; 
            fin.read(buffer); 
            res = EncodingUtils.getString(buffer, "GBK"); 
            fin.close(); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
        return res; 
    } 
}
